<template>
  <div class="warehouse-approve-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <super-table
        :height="tableHeight"
        ref="tableRef"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
        :sort-config="{ remote: true }"
        @sort-change="sortChangeHandle"
      >
        <template #tool>
          <a-button type="primary" @click="batchBillHandle">批量生成账单</a-button>
        </template>
        <template #isTransferBill="{ row }">
          <span v-if="row.isTransferBill === '1'">是</span>
          <span v-if="row.isTransferBill === '0'">否</span>
        </template>
        <template #warehouseBillNum="{ row }">
          <a-button type="link" @click="showApprovalHandle(row)">{{ row.warehouseBillNum }}</a-button>
        </template>
        <template #state="{ row }">
          <a-tag v-if="row.state === 3" color="#cccc"> 待审批 </a-tag>
          <a-tag v-if="row.state === 4" color="#f40"> 审批驳回 </a-tag>
          <a-tag v-if="row.state === 5" color="#87d068"> 审批通过 </a-tag>
        </template>
        <template #action="{ row }">
          <a-button type="link" @click="approvalHandle(row)" v-if="row.state !== 5">审批</a-button>
          <a-button type="link" @click="showApprovalHandle(row)">详情</a-button>
        </template>
      </super-table>
    </div>
    <!-- 抽屉 -->
    <a-drawer class="custom-drawer" v-model:visible="drawerOpts.visible" :title="drawerOpts.title" :maskClosable="false" :closable="true" :width="drawerOpts.width" placement="right">
      <component
        v-model:visible="drawerOpts.visible"
        :is="drawerOpts.component"
        :type="drawerOpts.type"
        :pass-data="drawerOpts.passData"
        @submit="drawerSubmitHandle"
        @reject="drawerSubmitHandle"
      ></component>
    </a-drawer>

    <!-- 弹窗 -->
    <a-modal
      v-model:visible="dialogOpts.visible"
      :maskClosable="false"
      :keyboard="false"
      :closable="['DataStatistics'].includes(dialogOpts.component)"
      :footer="null"
      :title="dialogOpts.title"
      :width="dialogOpts.width"
    >
      <component v-model:visible="dialogOpts.visible" :is="dialogOpts.component" :type="dialogOpts.type" :pass-data="dialogOpts.passData" @submit="dialogSubmitHandle"></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import Details from "./components/details/index.vue";
import CreateBill from "./components/createBill/index.vue";
import TableHook from "@/hook/tableHook";
export default {
  name: "WarehouseApprove",
  components: {
    Details,
    CreateBill
  }
};
</script>
<script setup lang="ts">
import TableHeightHook from "@/hook/tableHeightHook";
import InitHook from "./composables/initHook";
import ModalHook from "@/hook/modalHook";
import OperationHook from "./composables/operationHook";
import { searchItemList, tableColumn } from "./data";
const { tableHeight } = TableHeightHook(45);

const { searchForm, tableRef, tableData, drawerOpts, loading, dialogOpts } = InitHook();
const { searchHandle, getData, approvalHandle, batchBillHandle, showApprovalHandle } = OperationHook({
  searchForm,
  loading,
  tableData,
  drawerOpts,
  tableRef,
  dialogOpts
});
searchHandle();
const { sortChangeHandle } = TableHook({ searchForm }, getData);
const { drawerSubmitHandle, dialogSubmitHandle } = ModalHook({
  drawerOpts,
  callBack: () => {
    searchHandle();
  }
});
</script>
<style lang="stylus" scoped></style>
